package cheng.rui.hong.logic;


import java.util.ArrayList;
import java.util.List;

import cheng.rui.hong.frame.Frame;


public class MementoOperation {

	private String currentLine="";
    private double prevNum;
	private CalcEnum currentCalcEnum=CalcEnum.DEFAULT;
	private String prevInput="";
	
	private Frame frame;
	
	private String appedStr;
	
	static List<MementoOperation> memList=new ArrayList<MementoOperation>();
	
	public MementoOperation(Frame frame){
		this.frame=frame;
	}
	
	public String getCurrentLine() {
		return currentLine;
	}
	public void setCurrentLine(String currentLine) {
		this.currentLine = currentLine;
	}
	public double getPrevNum() {
		return prevNum;
	}
	public void setPrevNum(double prevNum) {
		this.prevNum = prevNum;
	}
	public CalcEnum getCurrentCalcEnum() {
		return currentCalcEnum;
	}
	public void setCurrentCalcEnum(CalcEnum currentCalcEnum) {
		this.currentCalcEnum = currentCalcEnum;
	}
	public String getPrevInput() {
		return prevInput;
	}
	public void setPrevInput(String prevInput) {
		this.prevInput = prevInput;
	}
	
	public void appCurrentLine(String appStr){
		setCurrentLine(currentLine+=appStr);
	}
	
	private MementoOperation copyOperation(){
		return new MementoOperation(frame);
		
	}
	
	
	public String getAppedStr() {
		return appedStr;
	}

	public void setAppedStr(String appedStr) {
		this.appedStr = appedStr;
	}

	public void appShowText(String appStr){
		MementoOperation copy=this.copyOperation();
		if(copy!=null){
		copy.setAppedStr(appStr);
		copy.setCurrentCalcEnum(currentCalcEnum);
		copy.setCurrentLine(currentLine);
		copy.setAppedStr(appStr);
		copy.setPrevInput(prevInput);
		copy.setPrevNum(prevNum);
		memList.add(copy);
		}
		frame.appShowText(appStr);
	}
	
	public MementoOperation cancel(){
		MementoOperation preCopy=memList.get(memList.size()-1);
		frame.removeStr(preCopy.getAppedStr());
		memList.remove(memList.size()-1);
		return preCopy;
	}
	
}
